/*
 * Copyright (c) 2005, 2014 vacoor
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.vacoor.nothing.security.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.vacoor.nothing.security.shiro.filter.mgt.CustomFilterChainManager;

import java.util.Map;

/**
 * @author vacoor
 */
@Controller
@RequestMapping("filter")
public class SecurityFilterController {
    @Autowired
    private CustomFilterChainManager filterChainManager;

    @RequestMapping
    public String index(Map<String, Object> model) {
        model.put("staticFilters", filterChainManager.getDefaultFilterChainDefinitionMap());
        model.put("dynamicFilters", filterChainManager.getDynamicFilterChainDefinitionMap());
        // ((OncePerRequestFilter)filterChainManager.getFilters().get(0)).setEnabled();
        return "filter/filter";
    }

    @RequestMapping("create")
    public void create(String url, String p) {
        Map<String, String> f = filterChainManager.getDynamicFilterChainDefinitionMap();
        f.put(url, p);
        filterChainManager.updateFilterChain();
    }
}
